import * as api from '../../service/api'

const state = {

  	userInfo : {},
  	systemList : [],
  	menuList : [],
  	systemName : '',
    accountBalance : [],

    userInfo1 : {},
    userAccount : {},
}

const getters = {
	userInfo : state => state.userInfo,
	systemList : state => state.systemList,
	menuList : state => state.menuList,
    systemName : state => state.systemName,
    accountBalance : state => state.accountBalance,

    userInfo1 : state => state.userInfo1,
	userAccount : state => state.userAccount,

}

const actions = {

	//用户信息，和拥有的系统信息和菜单信息
    async getUserInfo ({ commit, dispatch}, para) {
        let res1 = await api.userInfo();
        //let res2 = await api.systemList();
        //if(res2.errcode == 0 && res2.data.length > 0){
            commit('setUserInfo', res1);
            //commit('setSystemList', res2.data);
            //var sys = res2.data[0];
            let res3 = dispatch('getMenuList', {'id' : '143bf2ef757b4f3f94f5d3de0cef7b06'});
        //}

      //   let res1 = await api.userInfo();
      //   let res2 = await api.systemList();
      //   if(res2.errcode == 0 && res2.data.length > 0){
      //   	commit('setUserInfo', res1);
      //  		commit('setSystemList', res2.data);
    		// var sys = res2.data[0];
    		// let res3 = dispatch('getMenuList', {'id' : sys.id});
      //   }
    },


    //菜单信息
    async getMenuList ({ commit }, para) {
        let res = await api.menuList(para.id);
        if(res.errcode == 0){
            commit('setMenuList', res.data.list);
        	commit('setSystemName', res.data.name);
        }
    },


    //账户余额
    async getAccountBalance ({ commit }, para) {
        let res = await api.accountBalance();
        console.log('账户余额');
        console.log(res);
        if(res.errcode == 0){
            commit('setAccountBalance', res.data);
        }
    },
    
}

const mutations = {
	setUserInfo (state, obj) {
        state.userInfo = obj;
    },
    setSystemList (state, obj) {
        state.systemList = obj;
    },
    setMenuList (state, obj) {
        state.menuList = obj;
    },
    setSystemName (state, obj) {
        state.systemName = obj;
    },
    setAccountBalance (state, obj) {
        state.accountBalance = obj;
    },
    setUserInfo1 (state, obj) {
        state.userInfo1 = obj;
    },
    setUserAccount (state, obj) {
        state.userAccount = obj;
    },
}

export default {
  state,
  getters,
  actions,
  mutations
}
